﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using DispatchAssist.BusinessLogical.BLL;
using DispatchAssist.BusinessLogical.Model;
using DispatchAssist.Model;
using System.Web.Services.Protocols;

namespace DispatchAssist.WebService
{
    /// <summary>
    /// Summary description for AuthService
    /// </summary>
    [WebService(Namespace = "http://DispatchAssist.ceair.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class AuthService : System.Web.Services.WebService
    {
        #region Members.

        public DASoapHeader headerContext = new DASoapHeader();

        #endregion 

        [WebMethod(Description = "获取所有监控席位信息列表")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<SeatMonitor> GetSeatMonitors()
        {
            return AuthManager.Instance.GetSeatMonitors();
        }

        [WebMethod(Description = "创建监控席位信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public DispatchAssist.BusinessLogical.Model.Enums.DataAccessReturnValue CreateSeatMonitor(SeatMonitor seatMonitor)
        {
            return AuthManager.Instance.CreateSeatMonitor(seatMonitor);
        }

        [WebMethod(Description = "删除监控席位信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeleteSeatMonitor(Guid seatMonitorID)
        {
            return AuthManager.Instance.DeleteSeatMonitor(seatMonitorID);
        }

        [WebMethod(Description = "修改密码")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public BusinessLogical.Model.Enums.DataAccessReturnValue ChangePassword(SeatUser seatUser, byte[] oldPassword)
        {
            return AuthManager.Instance.ChangePassword(seatUser, oldPassword);
        }

        [WebMethod(Description = "获取所有系统模块信息列表")]
        //[SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        //[Validation(EnableLog = true)]
        public List<SystemModule> GetSystemModules()
        {
            return AuthManager.Instance.GetSystemModules();
        }

        [WebMethod(Description = "创建席位角色信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool CreateSeatRole(SeatRole seatRole)
        {
            if (headerContext.ValidateUser())
            {
                return AuthManager.Instance.CreateSeatRole(seatRole);
            }
            else
            {
                return false;
            }
        }



        [WebMethod(Description = "检查用户是否已登录")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool SeatUserIsLogin(Guid SeatID, string UserName)
        {
            return AuthManager.Instance.SeatUserIsLogin(SeatID, UserName);
        }

        [WebMethod(Description = "获取所有席位角色信息列表")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<SeatRole> GetAllSeatRole()
        {
            return AuthManager.Instance.GetAllSeatRole();
        }

        [WebMethod(Description = "根据RoleID更新席位角色信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool UpdateSeatRole(SeatRole seatRole)
        {
            return AuthManager.Instance.UpdateSeatRole(seatRole);
        }

        [WebMethod(Description = "删除席位角色信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeleteSeatRole(Guid roleID)
        {
            return AuthManager.Instance.DeleteSeatRole(roleID);
        }

        [WebMethod(Description = "获取所有席位用户信息列表")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<SeatUser> GetAllSeatUser(int flag)
        {
            return AuthManager.Instance.GetAllSeatUser(flag);
        }

        [WebMethod(Description = "创建席位用户信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool CreateSeatUser(SeatUser seatUser)
        {
            return AuthManager.Instance.CreateSeatUser(seatUser);
        }

        [WebMethod(Description = "删除席位用户信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeleteSeatUser(Guid userID, bool deleteFlag)
        {
            return AuthManager.Instance.DeleteSeatUser(userID, deleteFlag);
        }

        [WebMethod(Description = "更新席位用户信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool UpdateSeatUser(SeatUser seatUser)
        {
            return AuthManager.Instance.UpdateSeatUser(seatUser);
        }

        [WebMethod(Description = "根据Mac地址获取席位信息")]
        public Seat GetSeatByMac(string mac)
        {
            return AuthManager.Instance.GetSeatByMac(mac);
        }

        [WebMethod(Description = "根据SeatID、用户名、密码获取席位用户信息")]
        public SeatUser Login(string userName, byte[] password, Guid seatId)
        {
            return AuthManager.Instance.Login(userName, password, seatId);
        }

        [WebMethod(Description = "根据UserID和SeatID注销当前席位用户信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool Logout(Guid userId, Guid seatId)
        {
            return AuthManager.Instance.Logout(userId, seatId);
        }

        [WebMethod(Description = "获取所有席位信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<Seat> GetAllSeat()
        {
            return AuthManager.Instance.GetAllSeat();
        }

        [WebMethod(Description = "获取所有席位飞机对应关系")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<SeatTails> GetAllSeatTails()
        {
            return AuthManager.Instance.GetAllSeatTails();
        }

        [WebMethod(Description = "获取所有飞机类型")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<PlaneType> GetAllPlaneType()
        {
            return AuthManager.Instance.GetAllPlaneType();
        }

        [WebMethod(Description = "获取所有飞机号")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<ACARSDevice> GetAllTails()
        {
            return CommonCacheData.CacheACARDevice.AcarsDeviceList;
        }

        [WebMethod(Description = "保存席位飞机对应关系")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public string SaveSeatTails(Guid SeatID, string[] Tails)
        {
            return AuthManager.Instance.SaveSeatTails(SeatID, Tails);
        }

        [WebMethod(Description = "获取所有机型和机型下的飞机")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<PlaneType> GetAllTialsAndType()
        {
            return AuthManager.Instance.GetAllTailAndType();
        }

        [WebMethod(Description = "新增机型信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public string InsertPlaneType(PlaneType model)
        {
            return AuthManager.Instance.InsertPlaneType(model);
        }

        [WebMethod(Description = "更新机型信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public string UpdatePlaneType(PlaneType model)
        {
            return AuthManager.Instance.UpdatePlaneType(model);
        }

        [WebMethod(Description = "新增飞机信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public string InsertPlaneInfo(ACARSDevice model)
        {
            return AuthManager.Instance.InsertPlaneInfo(model);
        }

        [WebMethod(Description = "更新飞机信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public string UpdatePlaneInfo(ACARSDevice model)
        {
            return AuthManager.Instance.UpdatePlaneInfo(model);
        }

        [WebMethod(Description = "删除机型信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeletePlaneType(int TypeID, string ParentOrChild)
        {
            return AuthManager.Instance.DeletePlaneType(TypeID, ParentOrChild);
        }

        [WebMethod(Description = "删除飞机信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeletePlaneInfo(string tailNo)
        {
            return AuthManager.Instance.DeletePlaneInfo(tailNo);
        }



        [WebMethod(Description = "创建席位信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool CreateSeat(Seat seat)
        {
            return AuthManager.Instance.CreateSeat(seat);
        }

        [WebMethod(Description = "删除席位信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeleteSeat(Seat seat)
        {
            return AuthManager.Instance.DeleteSeat(seat);
        }

        [WebMethod(Description = "更新席位信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool UpdateSeat(Seat seat)
        {
            return AuthManager.Instance.UpdateSeat(seat);
        }

        [WebMethod(Description = "根据RoleID获取席位角色信息")]
        public SeatRole GetRoleByID(Guid roleId)
        {
            return AuthManager.Instance.GetRoleByID(roleId);
        }

        [WebMethod(Description = "获取所有通讯群组的信息列表")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<SMSContactGroup> GetContactGroup()
        {
            return AuthManager.Instance.GetContactGroup();
        }

        [WebMethod(Description = "创建SMS短信通讯群组信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public BusinessLogical.Model.Enums.DataAccessReturnValue CreateSMSContactGroup(SMSContactGroup group)
        {
            return AuthManager.Instance.CreateSMSContactGroup(group);
        }

        [WebMethod(Description = "更新SMS短信通讯群组信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public BusinessLogical.Model.Enums.DataAccessReturnValue UpdateSMSContactGroup(SMSContactGroup group)
        {
            return AuthManager.Instance.UpdateSMSContactGroup(group);
        }

        [WebMethod(Description = "删除SMS短信通讯群组信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeleteSMSContactGroup(Guid groupID)
        {
            return AuthManager.Instance.DeleteSMSContactGroup(groupID);
        }

        [WebMethod(Description = "获取所有SMS短信通讯信息列表")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public List<SMSContact> GetAllSMSContacts()
        {
            return AuthManager.Instance.GetAllSMSContacts();
        }

        [WebMethod(Description = "创建SMS短信通讯信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool CreateSMSContact(SMSContact contact)
        {
            return AuthManager.Instance.CreateSMSContact(contact);
        }

        [WebMethod(Description = "删除SMS短信通讯信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool DeleteSMSContact(Guid contactID)
        {
            return AuthManager.Instance.DeleteSMSContact(contactID);
        }

        [WebMethod(Description = "更新SMS短信通讯信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public bool UpdateSMSContact(SMSContact contact)
        {
            return AuthManager.Instance.UpdateSMSContact(contact);
        }

        [WebMethod(Description = "日志查询")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public string QueryLogCommon(string logTypeStr, QueryCondition qc)
        {
            object obj = SystemLogManager.QueryLogCommon(logTypeStr, qc);

            return ClientInfoCacheHelper.ReturnJsonStr(obj);

        }
        [WebMethod(Description = "获取弹框信息")]
        [SoapHeader("headerContext", Direction = SoapHeaderDirection.In)]
        [Validation(EnableLog = true)]
        public string GetAllAlertInfoData(Guid id, int action)
        {

            SystemLogManager.GetNewAlertInfoData(id, action);
            return ClientInfoCacheHelper.ReturnJsonStr(SystemLogManager.AlertInfoData);
        }



    }
}
